package com.budwk.app.sqfw.controllers.admin.datamange;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.budwk.app.sqfw.services.datamange.DataMangeCommunityService;
import com.budwk.app.sqfw.services.datamange.DataMangeMainService;
import com.budwk.app.sqfw.vo.SqfwDataMangeVO;
import com.budwk.starter.common.openapi.annotation.*;
import com.budwk.starter.common.result.Result;
import com.budwk.starter.log.annotation.SLog;
import lombok.extern.slf4j.Slf4j;
import org.nutz.integration.jedis.RedisService;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.mvc.annotation.*;

import java.util.List;

/**
 * @program: community-admin
 * @description: 数据管理-每级区域主表数据管理
 * @author: LJT
 * @create: 2024-05-31 16:45
 **/
@IocBean
@At("/platform/sqfw/datamange/main/")
@ApiDefinition(tag = "数据管理-每级区域主表（后台管理系统）")
@Slf4j
public class SqfwDataMangeMainController {

    @Inject
    private RedisService redisService;

    @Inject
    private DataMangeCommunityService sqfwFormsummaryOnlineService;

    @Inject
    private DataMangeMainService dataMangeMainService;

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "列表查询")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "create_date", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            },
            implementation = SqfwDataMangeVO.class
    )
    @ApiResponses(
            implementation = SqfwDataMangeVO.class
    )
    @SLog(tag = "公共列表查询（后台管理系统）", value = "${args[0]}}")
    @SaCheckLogin
    public Result<?> page(@Param("..") SqfwDataMangeVO bean,
                          @Param("pageNo") int pageNo,
                          @Param("pageSize") int pageSize,
                          @Param("pageOrderName") String pageOrderName,
                          @Param("pageOrderBy") String pageOrderBy) {
        return Result.data(dataMangeMainService.page(bean));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "列表查询")
    @ApiFormParams(
            value = {
                    @ApiFormParam(name = "pageNo", example = "1", description = "页码", type = "integer"),
                    @ApiFormParam(name = "pageSize", example = "10", description = "页大小", type = "integer"),
                    @ApiFormParam(name = "pageOrderName", example = "create_date", description = "排序字段"),
                    @ApiFormParam(name = "pageOrderBy", example = "descending", description = "排序方式")
            },
            implementation = SqfwDataMangeVO.class
    )
    @ApiResponses(
            implementation = SqfwDataMangeVO.class
    )
    @SLog(tag = "公共列表查询（后台管理系统）", value = "${args[0]}}")
    @SaCheckLogin
    public Result<?> pageSelf(@Param("..") SqfwDataMangeVO bean,
                          @Param("pageNo") int pageNo,
                          @Param("pageSize") int pageSize,
                          @Param("pageOrderName") String pageOrderName,
                          @Param("pageOrderBy") String pageOrderBy) {
        return Result.data(dataMangeMainService.pageSelf(bean));
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "添加数据")
    @ApiResponses
    @SLog(tag = "添加数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> save(@Param("..") SqfwDataMangeVO bean) {
        sqfwFormsummaryOnlineService.save(bean);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "抽取大数据")
    @ApiResponses
    @SLog(tag = "抽取大数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> parseDataBig(@Param("..") SqfwDataMangeVO bean) {
        sqfwFormsummaryOnlineService.parseDataBig(bean);
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "删除数据")
    @ApiResponses
    @SLog(tag = "删除数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> deleteData(@Param("ids") List<String> ids) {
        sqfwFormsummaryOnlineService.deleteData(ids);
        return Result.success();
    }

    @At
    @Ok("json")
    @DELETE
    @ApiOperation(name = "删除数据sss")
    @ApiResponses
    @SLog(tag = "删除数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> deletessss(@Param("..") SqfwDataMangeVO bean) {
        sqfwFormsummaryOnlineService.clear();
        return Result.success();
    }

    @At
    @Ok("json")
    @POST
    @ApiOperation(name = "更新数据")
    @ApiResponses
    @SLog(tag = "更新数据", value = "${args[0]}")
    @SaCheckLogin
    public Result<?> updateData(@Param("..") SqfwDataMangeVO bean) {
        sqfwFormsummaryOnlineService.updateData(bean);
        return Result.success();
    }
}
